package cn.tedu._06interceptor.config;

import cn.tedu._06interceptor.interceptor.MyInterceptor01;
import cn.tedu._06interceptor.interceptor.MyInterceptor02;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置类
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //策略1：拦截所有请求
//        registry.addInterceptor(new MyInterceptor01());
        //策略2：拦截制定请求，比如登录请求、注册请求
//        registry.addInterceptor(new MyInterceptor01())
//                .addPathPatterns("/v1/users/login","/v1/users/reg");
        //策略3：拦截指定的一类请求，比如某个模块的请求
//        registry.addInterceptor(new MyInterceptor01())
//                .addPathPatterns("/v1/users/**");
        //策略4：排除/不拦截指定的请求
//        registry.addInterceptor(new MyInterceptor01())
//                .excludePathPatterns("/v1/users/login");
        //策略5：排除指定的一类请求
//        registry.addInterceptor(new MyInterceptor01())
//                .excludePathPatterns("/v1/users/**");

        registry.addInterceptor(new MyInterceptor01());
        registry.addInterceptor(new MyInterceptor02());
    }
}
